package com.mark.vo;

import com.mark.enums.OrderStatusEnum;
import com.mark.pojo.OrderItem;
import com.mark.util.DateTimeUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.math.BigDecimal;

/**
 * Created by Mark on 2018/3/30.
 * 订单子明细Vo封装
 */

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class OrderItemVo {

    private Integer id;                     //ID
    private Long orderNo;                   //订单号
    private Integer productId;              //商品ID
    private Integer sellerId;               //卖家ID
    private String sellerName;              //卖家姓名
    private String productName;             //产品的名称
    private String productImage;            //主图
    private BigDecimal currentUnitPrice;    //价格
    private Integer quantity;               //数量
    private BigDecimal totalPrice;          //总价
    private Integer enableStatus;           //订单的状态
    private String enableStatusDes;         //订单的状态描述
    private String operation;               //操作
    private String createTime;              //创建时间
    private String paymentTime;             //支付时间
    private String sendTime;                //发货时间
    private String endTime;                 //结束时间


    public OrderItemVo assembleOrderItemVo(OrderItem orderItem) {
        OrderItemVo orderItemVo = new OrderItemVo();
        orderItemVo.setId(orderItem.getId());
        orderItemVo.setOrderNo(orderItem.getOrderNo());
        orderItemVo.setProductId(orderItem.getProductId());
        orderItemVo.setSellerId(orderItem.getSellerId());
        orderItemVo.setProductName(orderItem.getProductName());
        orderItemVo.setProductImage(orderItem.getProductImg());
        orderItemVo.setCurrentUnitPrice(orderItem.getCurrentUnitPrice());
        orderItemVo.setQuantity(orderItem.getQuantity());
        orderItemVo.setTotalPrice(orderItem.getTotalPrice());
        orderItemVo.setEnableStatus(orderItem.getEnableStatus());
        if(orderItem.getEnableStatus() != null){
            orderItemVo.setEnableStatusDes(OrderStatusEnum.codeOf(orderItem.getEnableStatus()).getInformation());
            orderItemVo.setOperation(assembleOperation(orderItem.getEnableStatus()));
        }
        orderItemVo.setCreateTime(DateTimeUtil.dateToStr(orderItem.getCreateTime()));
        orderItemVo.setPaymentTime(DateTimeUtil.dateToStr(orderItem.getPaymentTime()));
        orderItemVo.setSendTime(DateTimeUtil.dateToStr(orderItem.getSendTime()));
        orderItemVo.setEndTime(DateTimeUtil.dateToStr(orderItem.getEndTime()));
        return orderItemVo;
    }

    private String assembleOperation(Integer enableStatus) {//组装订单的状态
        switch (enableStatus){
            case 0: return "已取消";
            case 10 : return "去取消";
            case 20 : return "等待发货";
            case 40 : return "确认收货";
            case 50 : return "去评论";
            case 60 : return "去评论";
            default: return "不明确";
        }
    }
}
